
let dataDemo = {
    data: [
        /*
        {
            userId:1,
            rankScore: 0,
            avatarUrl: '',
            nickname: '',
        },
        */
    ],
    selfData: {
        /*
        {
            rankNum:0,
            rankScore: 0,
            avatarUrl: '',
            nickname: '',
        },
       */
    }
};


function createItem(friendData, userData) {
    dataDemo.data = [];
    console.log("friendData", friendData, userData)
    if (!friendData) {
        return dataDemo;
    }
    let length = friendData.length;
    let isExitPerson = 0;
    for (let i = 0; i < length; ++i) {
        let playerInfo = friendData[i];
        let item = {};
        item.userId = i + 1;
        if (playerInfo.KVDataList) {
            item.rankScore = playerInfo.KVDataList.length != 0 ? playerInfo.KVDataList[0].value : 0;
            item.avatarUrl = playerInfo.avatarUrl;//'openDataContext/render/avatar.png';//
            item.nickname = playerInfo.nickname;
        }
        else {
            item.rankScore = 1;
            item.avatarUrl = playerInfo.avatarUrl;//'openDataContext/render/avatar.png';//
            item.nickname = playerInfo.nickName;
        }
        dataDemo.data.push(item);
        let isDff = userData.avatarUrl == item.avatarUrl;
        let isDff1 = userData.nickName == item.nickname;
        if (isDff && isDff1) {
            isExitPerson = 1;
            dataDemo.selfData = {
                rankNum: i + 1,
                rankScore: item.rankScore,
                avatarUrl: item.avatarUrl,
                nickname: item.nickname,
            }
        }
    }
    if (isExitPerson == 0) {
        dataDemo.selfData = {
            rankNum: length + 1,
            rankScore: 1,
            avatarUrl: userData.avatarUrl,
            nickname: userData.nickName,
        }
    }
    dataDemo.data.sort((a, b) => b.rankScore - a.rankScore);
    return dataDemo;
}
export default createItem